package com.java.second_goods.controller;

import com.java.second_goods.common.AjaxResult;
import com.java.second_goods.entity.Chef;
import com.java.second_goods.service.ChefService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 厨师信息
 */
@RestController
@RequestMapping("/api/chef")
@Tag(name = "厨师管理", description = "厨师相关接口")
public class ChefController extends BaseController {

    @Autowired
    private ChefService chefService;

    /**
     * 获取厨师列表
     */
    @GetMapping("/list")
//    @Operation(summary = "获取厨师列表", description = "获取厨师列表")
    public AjaxResult list(Chef chef) {
        startPage(1, 10);
        List<Chef> list = chefService.selectChefList(chef);
        return getDataTable(list);
    }

    /**
     * 获取厨师详细信息
     */
    @GetMapping("/{id}")
//    @Operation(summary = "获取厨师详细信息", description = "根据厨师ID获取厨师详细信息")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(chefService.selectChefById(id));
    }

    /**
     * 新增厨师
     */
    @PostMapping
//    @Operation(summary = "新增厨师", description = "新增厨师")
    public AjaxResult add(@RequestBody Chef chef) {
        return toAjax(chefService.insertChef(chef));
    }

    /**
     * 修改厨师
     */
    @PutMapping
//    @Operation(summary = "修改厨师", description = "修改厨师")
    public AjaxResult edit(@RequestBody Chef chef) {
        return toAjax(chefService.updateChef(chef));
    }

    /**
     * 删除厨师
     */
    @DeleteMapping("/{ids}")
//    @Operation(summary = "删除厨师", description = "删除厨师")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(chefService.deleteChefByIds(ids));
    }

    /**
     * 获取热门厨师列表
     */
    @GetMapping("/popular")
//    @Operation(summary = "获取热门厨师列表", description = "获取热门厨师列表")
    public AjaxResult getPopularChefs(@RequestParam(value = "limit", defaultValue = "6") Integer limit) {
        List<Chef> chefs = chefService.selectPopularChefs(limit);
        return success(chefs);
    }

    /**
     * 根据菜系查询厨师列表
     */
    @GetMapping("/category/{categoryId}")
//    @Operation(summary = "根据菜系查询厨师列表", description = "根据菜系ID查询厨师列表")
    public AjaxResult getChefsByCategory(@PathVariable("categoryId") Integer categoryId) {
        List<Chef> chefs = chefService.selectChefsByCategoryId(categoryId);
        return success(chefs);
    }

    /**
     * 更新厨师评分
     */
    @PutMapping("/rating/{chefId}/{rating}")
//    @Operation(summary = "更新厨师评分", description = "更新厨师评分")
    public AjaxResult updateRating(@PathVariable("chefId") Integer chefId,
                                   @PathVariable("rating") Double rating) {
        return toAjax(chefService.updateChefRating(chefId, rating));
    }

    /**
     * 设置厨师热门状态
     */
    @PutMapping("/popular/{chefId}/{isPopular}")
//    @Operation(summary = "设置厨师热门状态", description = "设置厨师热门状态")
    public AjaxResult setPopular(@PathVariable("chefId") Integer chefId,
                                 @PathVariable("isPopular") Boolean isPopular) {
        return toAjax(chefService.setChefPopular(chefId, isPopular));
    }
}